home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_03 / saks / polygon.h < prev    next >
C/C++ Source or Header  |  1994-01-12  |  870b  |  64 lines

  1. Listing 3 - the shape hierarchy with rectangle and triangle 
  2. derived from abstract base class polygon
  3.  
  4. class shape
  5.     {
  6. public:
  7.     ...
  8.     virtual shape *clone() const = 0;
  9.     ...
  10.     };
  11.  
  12. ...
  13.  
  14. class circle : public shape
  15.     {
  16. public:
  17.     shape *clone() const;
  18.     ...
  19.     };
  20.  
  21. shape *circle::clone() const
  22.     {
  23.     return new circle(*this);
  24.     }
  25.  
  26. ...
  27.  
  28. class polygon : public shape
  29.     {
  30. public:
  31. //  shape *clone() const = 0;   // still pure
  32.     ...
  33.     };
  34.  
  35. ...
  36.  
  37. class rectangle : public polygon
  38.     {
  39. public:
  40.     shape *clone() const;
  41.     ...
  42.     };
  43.  
  44. shape *rectangle::clone() const
  45.     {
  46.     return new rectangle(*this);
  47.     }
  48.  
  49. ...
  50.  
  51. class triangle : public polygon
  52.     {
  53. public:
  54.     shape *clone() const;
  55.     ...
  56.     };
  57.  
  58. shape *triangle::clone() const
  59.     {
  60.     return new triangle(*this);
  61.     }
  62.  
  63. ...
  64.